#include "TcpWaiter.h"

class Buff_Reader;


TcpWaiter::TcpWaiter(void)
{
}

TcpWaiter::TcpWaiter( unsigned short port, Buff_Reader *br )
{
	OS_SockAddr sa(port);
	if (-1 == m_sock.Open(sa,true)){
		return;
	}
	Br = br;
	bRun = true;
	m_sock.Listen();
}

TcpWaiter::~TcpWaiter(void)
{
	m_sock.Close();
	if (Br)
		delete Br;
}

int TcpWaiter::Routine()
{
	OS_TcpSocket acc;
	while (bRun)
	{
		if (-1 != m_sock.Accept(&acc))
		{
			if (Br)
				Br->coming(acc);
		}
	}
	return 0;
}